package com.borrow.controller;

import com.borrow.service.BorrowService;
import com.commons.entity.ResultFul;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/borrow")
@EnableHystrix  //启用Hystrix
public class BorrowController {
    @Resource
    private BorrowService borrowService;

    @GetMapping("{sid}")
//    @HystrixCommand(fallbackMethod = "findBorrowDetailsBySidBackupWay") //指明备选的接口方案
    public ResultFul findBorrowDetailsBySid(@PathVariable("sid") Integer sid){
        System.out.println("开始查阅信息");
        return borrowService.findBorrowDetailsBySid(sid);
    }

//    public ResultFul findBorrowDetailsBySidBackupWay(@PathVariable("sid") Integer sid){ //仍旧返回一样东西，但是不报错
//        System.out.println("某项服务中断，开始执行备选方案");
//        return ResultFul.success("{}","信息查询成功！");
//    }
}
